﻿using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
using UnityEngine.UI;

public class UIOrderParse 
{
    protected object[] parameters;
    protected BasePanel panel;

    public UIOrderParse(BasePanel panel) {
        this.panel = panel;
    }

    //对传进来的命令进行解析，选择合适的方法进行调用
    public void Parse(string order, BaseUIElement uiElement) {
        if (order == "") return;
        string[] strs = order.Split(':');
        string methodName = strs[0];
        string[] parameters = strs.Length > 1 ? strs[1].Split(',') : null;
        this.parameters = parameters;

        MethodInfo method = this.GetType().GetMethod(methodName);

        //方法不存在则报错
        if (method == default(MethodInfo)) {
            Debug.LogError("UI元素 " + uiElement.name + " 上的命令不存在");
            return;
        }

        method.Invoke(this, new object[] { uiElement });
    }
}
